use log::info;
use std::rc::Rc;
use yew::prelude::*;
/**
 * 个人信息实体
 */
pub struct UserInfo {
    // name: &str,
    pub age: i32,
    // job: &str,
}

// 定义操作的action
pub enum UserInfoAction {
    // UpdateName(&str),
    UpdateAge(i32),
}

impl Default for UserInfo {
    fn default() -> Self {
        Self { age: 28 }
    }
}
// action reducer
impl Reducible for UserInfo {
    type Action = UserInfoAction;

    fn reduce(self: Rc<Self>, action: Self::Action) -> Rc<Self> {
        match action {
            // UserInfoAction::UpdateName(name) => {
            //     self.name = name;

            //     Self { name }.into()
            // }
            UserInfoAction::UpdateAge(age) => {
                // self.age = age;
                info!("update age --- {age}");
                Self { age }.into()
            }
        }
    }
}
